﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.manager
{
    public partial class Operator : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                QueryData();
            }
        }

        public override void QueryData()
        {
            DataSet ds = null;
            if (!string.IsNullOrEmpty(Request["groupid"]))
                ds = PhoneBook.Users.Users.listgroupmanager(Commons.StrUtil.FormatValue(Request["groupid"]));
            else
                ds = PhoneBook.Users.Users.listmanager();
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }

        public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "del":
                    string userid = e.CommandArgument.ToString();

                    Hashtable user = PhoneBook.Users.Users.get(userid);
                    //超级管理员不会被删除
                    if (user["usertype"] == null || user["usertype"].ToString() == "0")
                    {
                        Helper.ShowMessage(u_message, controls.UCMessageType.attention, "超级管理员不能被删除");
                        return;
                    }
                    if (Session["userid"].Equals(userid))
                    {
                        Helper.ShowMessage(u_message, controls.UCMessageType.attention, "不允许删除自己的帐号");
                        return;
                    }
                    PhoneBook.Users.Users.del(userid);
                    Helper.ShowMessage(u_message, controls.UCMessageType.success, "删除成功");
                    AddLog("删除了管理员：{0}({1})", user["username"], user["userid"]);
                    QueryData();
                    break;
                default:
                    break;
            }
        }
    }
}